<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Person {
            constructor(name, age) { // 构造函数，调用new 自动执行
                console.log(`构造函数执行了${name}--${age}`);
                this.name = name;
                this.age = age
            }
            showname() {
                return `名字为:${this.name} `
            }
            shoage() {
                return `年龄为:${this.age}岁`
            }
        };

        let p1 = new Person('张三', 10);
        console.log(p1.showname(), p1.shoage());
    </script>




    <script>
        const Stu = class {
            constructor(name, age) {
                this.name = name;
                this.age = age;
            }
            showname() {
                return `名字为：${this.name} `
            }
            showage() {
                return `名字为:${this.age}  `
            }
        };
        let p2 = new Stu('小刘', 9);
        console.log(p2.showname(), p2.showage());
    </script>
</body>

</html>